﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsProductTypeDAL.cs
/// 作  者：SAM
/// 时  间：2006.11.10
/// 说  明：ClsProductTypeDAL类用于商品类别信息相关处理
/// </summary>
public class ClsProductTypeDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有的商品类别信息
    /// </summary>
    /// <param name="Co_ID">公司ID</param>
    /// <param name="User_ID">用户ID</param>
    /// <param name="Ds_ID">数据集ID</param>
    /// <returns>返回商品类别信息数据集</returns>
    public DataSet GetProductTypes(string Co_ID, string User_ID, string Ds_ID)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetProductType", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        //dat.SelectCommand.Parameters.Add("@co_id", Co_ID);
        //dat.SelectCommand.Parameters.Add("@user_id", User_ID);
        //dat.SelectCommand.Parameters.Add("@ds_id", Ds_ID);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 搜索商品类别信息
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <returns>返回搜索信息数据集</returns>
    public DataSet SearchProductTypes(string Key)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchProductTypes", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 作废商品类别信息
    /// </summary>
    /// <param>商品类别编号</param>
    /// <param name="Is_Visible">作废状态1为临时作废，－1为彻底作废</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteProductType(string ID, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteProductType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 20);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@is_visible", SqlDbType.Int, 1);
        com.Parameters["@is_visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认商品类别信息
    /// </summary>
    /// <param>商品类别编号</param>
    /// <param name="AuditStat">确认状态</param>
    /// <param name="Auditor">确认人</param>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatProductType(string ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetProductType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 20);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加商品类别信息
    /// </summary>
    /// <param>商品类别编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddProductType(string ID, string Name,string UP, string Remark, string Oper, bool strCr_it_mmp, bool strCr_it_is_effdate, DateTime strCr_it_effdate, int strCr_it_warnmode, DateTime strCr_it_warndate)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddProductType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 20);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@name", SqlDbType.NVarChar, 20);
        com.Parameters["@name"].Value = Name;
        com.Parameters.Add("@it_up", SqlDbType.NVarChar, 20);
        com.Parameters["@it_up"].Value = UP;
        //中间插入各表的数据和参数
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 60);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        com.Parameters.Add("@it_mmp", SqlDbType.Bit);
        com.Parameters["@it_mmp"].Value = strCr_it_mmp;
        com.Parameters.Add("@it_is_effdate", SqlDbType.Bit);
        com.Parameters["@it_is_effdate"].Value = strCr_it_is_effdate;
        com.Parameters.Add("@it_effdate", SqlDbType.DateTime, 8);
        com.Parameters["@it_effdate"].Value = strCr_it_effdate;
        com.Parameters.Add("@it_warnmode", SqlDbType.NVarChar, 30);
        com.Parameters["@it_warnmode"].Value = strCr_it_warnmode;
        com.Parameters.Add("@it_warndate", SqlDbType.DateTime,8);
        com.Parameters["@it_warndate"].Value = strCr_it_warndate;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改商品类别信息
    /// </summary>
    /// <param>商品类别编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateProductType(string ID, string Name, string it_up,string Remark, bool strCr_it_mmp, bool strCr_it_is_effdate, DateTime strCr_it_effdate, int strCr_it_warnmode, DateTime strCr_it_warndate)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateProductType", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 20);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@name", SqlDbType.NVarChar, 30);
        com.Parameters["@name"].Value = Name;
        com.Parameters.Add("@it_up", SqlDbType.NVarChar, 30);
        com.Parameters["@it_up"].Value = it_up;
        //中间插入各表的数据和参数

        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        com.Parameters.Add("@it_mmp", SqlDbType.Bit);
        com.Parameters["@it_mmp"].Value = strCr_it_mmp;
        com.Parameters.Add("@it_is_effdate", SqlDbType.Bit);
        com.Parameters["@it_is_effdate"].Value = strCr_it_is_effdate;
        com.Parameters.Add("@it_effdate", SqlDbType.DateTime, 8);
        com.Parameters["@it_effdate"].Value = strCr_it_effdate;
        com.Parameters.Add("@it_warnmode", SqlDbType.Int);
        com.Parameters["@it_warnmode"].Value = strCr_it_warnmode;
        com.Parameters.Add("@it_warndate", SqlDbType.DateTime, 8);
        com.Parameters["@it_warndate"].Value = strCr_it_warndate;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 用于查询商品类别窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchProductTypeSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByProductType", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 用于查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet GetUpProductSch()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetUpProductSch", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }
}
